/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
import com.adobe.test.Assert;
 //-----------------------------------------------------------------------------
// var SECTION = "RegExp/properties-002.js";
// var VERSION = "ECMA_2";
// var TITLE   = "Properties of RegExp Instances";
var BUGNUMBER ="http://scopus/bugsplat/show_bug.cgi?id=346032";
// ALSO SEE http://bugzilla.mozilla.org/show_bug.cgi?id=124339

var testcases = getTestCases();

function getTestCases() {
    var array = new Array();
    var item = 0;

    re_1 = /\cA?/g;
    re_1.lastIndex = Math.pow(2,30);
    AddRegExpCases( re_1, "\\cA?", true, false, false, Math.pow(2,30) );

    re_2 = /\w*/i;
    re_2.lastIndex = Math.pow(2,30) -1;
    AddRegExpCases( re_2, "\\w*", false, true, false, Math.pow(2,30)-1 );

    re_3 = /\*{0,80}/m;
    re_3.lastIndex = Math.pow(2,30) -1;
    AddRegExpCases( re_3, "\\*{0,80}", false, false, true, Math.pow(2,30) -1 );

    re_4 = /^./gim;
    re_4.lastIndex = Math.pow(2,30) -1;
    AddRegExpCases( re_4, "^.", true, true, true, Math.pow(2,30) -1 );

    re_5 = /\B/;
    re_5.lastIndex = Math.pow(2,30);
    AddRegExpCases( re_5, "\\B", false, false, false, Math.pow(2,30) );

    /*
     * Brendan: "need to test cases Math.pow(2,32) and greater to see
     * whether they round-trip." Reason: thanks to the work done in
     * http://bugzilla.mozilla.org/show_bug.cgi?id=124339, lastIndex
     * is now stored as a double instead of a uint32 (unsigned integer).
     *
     * Note 2^32 -1 is the upper bound for uint32's, but doubles can go
     * all the way up to Number.MAX_VALUE. So that's why we need cases
     * between those two numbers.
     *
     */
    re_6 = /\B/;
    re_6.lastIndex = Math.pow(2,30);
    AddRegExpCases( re_6, "\\B", false, false, false, Math.pow(2,30) );

    re_7 = /\B/;
    re_7.lastIndex = Math.pow(2,29) + 1;
    AddRegExpCases( re_7, "\\B", false, false, false, Math.pow(2,29) + 1 );

    re_8 = /\B/;
    re_8.lastIndex = Math.pow(2,29) * 2;
    AddRegExpCases( re_8, "\\B", false, false, false, Math.pow(2,29) * 2 );

    re_9 = /\B/;
    re_9.lastIndex = Math.pow(2,30);
    AddRegExpCases( re_9, "\\B", false, false, false, Math.pow(2,30) );


    function AddRegExpCases( re, s, g, i, m, l ){

        array[item++] = Assert.expectEq(
                     re + ".toString == RegExp.prototype.toString",
                     true,
                     re.toString == RegExp.prototype.toString );

        array[item++] = Assert.expectEq(
                     re + ".constructor == RegExp.prototype.constructor",
                     true,
                     re.constructor == RegExp.prototype.constructor );

        array[item++] = Assert.expectEq(
                     re + ".compile == RegExp.prototype.compile",
                     true,
                     re.compile == RegExp.prototype.compile );

        if (false) {
            array[item++] = Assert.expectEq(
                         re + ".test == RegExp.prototype.test",
                         true,
                         re.test == RegExp.prototype.test );
    
            array[item++] = Assert.expectEq(
                         re + ".exec == RegExp.prototype.exec",
                         true,
                         re.exec == RegExp.prototype.exec );
        }
        // properties

        array[item++] = Assert.expectEq(
                     re + ".source",
                     s,
                     re.source );

        array[item++] = Assert.expectEq(
                     re + ".toString()",
                     "/" + s +"/" + (g?"g":"") + (i?"i":"") +(m?"m":""),
                     re.toString() );

        array[item++] = Assert.expectEq(
                     re + ".global",
                     g,
                     re.global );

        array[item++] = Assert.expectEq(
                     re + ".ignoreCase",
                     i,
                     re.ignoreCase );

        array[item++] = Assert.expectEq(
                     re + ".multiline",
                     m,
                     re.multiline);

        array[item++] = Assert.expectEq(
                     re + ".lastIndex",
                     l,
                     re.lastIndex  );
    }

    return array;
}
